package com.epoint.juc.provider;

import java.util.concurrent.TimeUnit;

public class Msg {

    private int count = 0;

    public synchronized void send() throws InterruptedException {
        while (true){
            TimeUnit.MILLISECONDS.sleep(500);
            // 消费
            if(count > 0){
                System.out.println("消费者当前数量：" + count--);
                this.notifyAll();
            }

            this.wait();
        }
    }

    public synchronized void read() throws InterruptedException {
        while (true){
            TimeUnit.MILLISECONDS.sleep(500);
            // 生产
            if(count == 0){
                System.out.println("生产者当前数量：" + count++);
                this.notifyAll();
            }

            this.wait();
        }
    }
}
